import request from '@/utils/request'
import type { CategoryResponseData, AttrResponseData, Attr } from './type'
enum API {
  // 商品属性一级分类查询
  CATEGORY1_URL = '/admin/product/getCategory1',
  // 商品属性二级分类查询
  CATEGORY2_URL = '/admin/product/getCategory2',
  // 商品属性三级分类查询
  CATEGORY3_URL = '/admin/product/getCategory3',
  // 获取分类下对应的属性和属性值集合
  ATTR_URL = '/admin/product/attrInfoList',
  // 添加或者修改已有的属性的接口
  ADD_OR_UPDATE_ATTR_URL = '/admin/product/saveAttrInfo',
  // 删除某一个已有的属性
  DELETE_ATTR_URL = '/admin/product/deleteAttr',
}

// 获取商品属性一级分类
export const reqCategory1 = () =>
  request.get<any, CategoryResponseData>(API.CATEGORY1_URL)
// 根据商品一级分类id获取商品属性二级分类
export const reqCategory2 = (category1Id: number | string) =>
  request.get<any, CategoryResponseData>(`${API.CATEGORY2_URL}/${category1Id}`)
// 根据商品二级分类id获取商品属性三级分类
export const reqCategory3 = (category2Id: number | string) =>
  request.get<any, CategoryResponseData>(`${API.CATEGORY3_URL}/${category2Id}`)
// 获取分类下对应的属性和属性值集合
export const reqAttr = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) =>
  request.get<any, AttrResponseData>(
    `${API.ATTR_URL}/${category1Id}/${category2Id}/${category3Id}`,
  )

// ADD_OR_UPDATE_ATTR_URL
export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.ADD_OR_UPDATE_ATTR_URL, data)

// 删除属性
export const reqDeleteAttr = (attrId: number) =>
  request.delete<any, any>(`${API.DELETE_ATTR_URL}/${attrId}`)
